@{
    Layout = null;
}

<link href="~/libs\layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />

<form class="layui-form layui-form-pane" action="" lay-filter="editForm">
    <input type="hidden" name="id" />

    <div class="layui-form-item">
        <label class="layui-form-label">仓库编码</label>
        <div class="layui-input-block">
            <input type="text" name="warehouseCode" lay-verify="required" placeholder="请输入仓库编码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">仓库名称</label>
        <div class="layui-input-block">
            <input type="text" name="warehouseName" lay-verify="required" placeholder="请输入仓库名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">位置</label>
        <div class="layui-input-block">
            <input type="text" name="location" placeholder="请输入位置" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">面积</label>
        <div class="layui-input-block">
            <input type="number" name="warehouseArea" lay-verify="required|number" placeholder="请输入面积" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">负责人</label>
        <div class="layui-input-block">
            <input type="text" name="warehouseHead" placeholder="请输入负责人" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="radio" name="isFreeze" value="true" title="是" checked />
            <input type="radio" name="isFreeze" value="false" title="否" />
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.5.6/layui/layui.js"></script>

<script>
    layui.use(['form'], function(){
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;

        // 加载数据方法
        window.loadData = function(id) {
            console.log('加载数据方法被调用');
            $.get('/WarehouseSetup/GetWarehouseSetupById', { id: id }, function(res){
                console.log('获取到的数据:', res);
                if(res.code === "0"){
                    var formData = {
                        id: res.data.result.id,
                            warehouseCode: res.data.result.warehouseCode,
                        warehouseName: res.data.result.warehouseName,
                        location: res.data.result.location,
                        warehouseArea: res.data.result.warehouseArea,
                        warehouseHead: res.data.result.warehouseHead,
                        isFreeze: res.data.result.isFreeze ? "true" : "false"

                    };
                    form.val('editForm', formData);
                    form.render();
                } else {
                    layer.msg('获取数据失败');
                }
            });
        }

        // 监听提交
        form.on('submit(saveBtn)', function(data){
            $.ajax({
                url: '/WarehouseSetup/UpdateWarehouseSetup',
                type: 'POST',
                data: data.field,
                success: function(res){
                    console.log('保存结果:', res);
                    if(res > 0){
                        alert('保存成功');
                        // 刷新父页面表格
                        parent.layui.table.reload('warehouseTable');
                        // 关闭弹窗
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }else{
                        alert('保存失败');
                    }
                }
            });
            return false;
        });
    });
</script> 